package me.abc.hbase.access.test;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.client.*;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Test;

import java.io.IOException;

/**
 * Created by xiu on 15-11-12.
 */
public class HbaseAccess_TestModule {
    @Test
    public void test() throws IOException {
        System.setProperty("hadoop.home.dir", "E:\\ExternalLib\\hadoop-common-2.2.0-bin-master\\");

        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum", "192.168.1.108");
//        conf.set("hbase.zookeeper.quorum", "xiu-laptop");
//        HTable table = new HTable(conf, "test1");
//        Get get = new Get(Bytes.toBytes("row1"));
//        Result result = table.get(get);
//        for (KeyValue kv : result.raw()){
//            System.out.printf(String.format(new String(kv.getValue())));
//        }

        Scan scan = new Scan();
        ResultScanner rs = null;
        HTable table = new HTable(conf, Bytes.toBytes("test1222"));
        try {
            rs = table.getScanner(scan);
            for (Result r : rs) {
                for (KeyValue kv : r.list()) {
                    System.out.println("row:" + Bytes.toString(kv.getRow()));
                    System.out.println("family:"
                            + Bytes.toString(kv.getFamily()));
                    System.out.println("qualifier:"
                            + Bytes.toString(kv.getQualifier()));
                    System.out
                            .println("value:" + Bytes.toString(kv.getValue()));
                    System.out.println("timestamp:" + kv.getTimestamp());
                    System.out
                            .println("-------------------------------------------");
                }
            }
        } finally {
            rs.close();
        }
    }
}
